package com.chain.qs.modules.biz.service;

import com.chain.qs.common.service.CrudService;
import com.chain.qs.modules.biz.dao.EquipmentParameterDao;
import com.chain.qs.modules.biz.entity.EquipmentItemWarningRule;
import com.chain.qs.modules.biz.entity.EquipmentParameter;
import com.chain.qs.modules.biz.entity.EventTemplateItem;
import com.chain.qs.modules.biz.entity.WarningRecord;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
//@Transactional(readOnly = true)
public class EquipmentParameterService extends CrudService<EquipmentParameterDao, EquipmentParameter> {
    @Resource
    private WarningRecordService warningRecordService;
    @Resource
    private EquipmentItemWarningRuleService equipmentItemWarningRuleService;
    @Resource
    private EventTemplateItemService eventTemplateItemService;

    public List<EquipmentParameter> paramList(String equipmentId) {
        return dao.paramList(equipmentId);
    }

    public List<EquipmentParameter> itemParamList(String itemId) {
        return dao.itemParamList(itemId);
    }

    public EquipmentParameter getOne(EquipmentParameter parameter) {
        return dao.getOne(parameter);
    }

    public void delete(EquipmentParameter equipmentParameter) {
        for (WarningRecord warningRecord : warningRecordService.findList(new WarningRecord(null, null, equipmentParameter.getId(), null))) {
            warningRecordService.delete(warningRecord);
        }
        for (EquipmentItemWarningRule equipmentItemWarningRule : equipmentItemWarningRuleService.findListByParamId(equipmentParameter.getId())) {
            equipmentItemWarningRuleService.delete(equipmentItemWarningRule);
        }
        for (EventTemplateItem eventTemplateItem : eventTemplateItemService.findListByParamId(equipmentParameter.getId())) {
            eventTemplateItemService.delete(eventTemplateItem);
        }
        super.delete(equipmentParameter);
    }
}
